package com.d2.upload.controller;


import com.d2.common.domain.Result;
import com.d2.upload.entity.AmazonFileModel;
import com.d2.upload.service.AmazonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@Slf4j
public class FileUploadController {

    @Autowired
    AmazonService amazonService;


    @PostMapping(value = "/upload")
    public Result<AmazonFileModel> upload(@RequestParam("file") MultipartFile file) {
        AmazonFileModel amazonFileModel;
        try {
            amazonFileModel = amazonService.upload(file);
            return Result.success(amazonFileModel);
        }catch (Exception e){
            return Result.error("文件上传失败");
        }
    }
}